package cn.songhaiqing.walle.bean;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.IBinder;
import android.os.StrictMode;
import android.util.Log;
import android.widget.SlidingDrawer;


import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Locale;

import cn.songhaiqing.walle.Event.ServiceRegistSuccessEvent;
import cn.songhaiqing.walle.global.Global;
import cn.songhaiqing.walle.service.BLEService;
import cn.songhaiqing.walle.service.BLEService2;

public class MyApp extends Application {
    public static boolean isHeartSetContinue = false;
    public static boolean isHeartSetWork = false;
    private static MyApp myApp;
    // public static Locale systemDefaultLocale = LaguageHelper.getDefaultLanguage();
    public int densityDPI;
    private SharedPreferences.Editor editor;
    public Typeface face = null;
    public Typeface face_number = null;
    private String filePath;
    public boolean isAriUpWork = false;
    public boolean isSending = false;
    public ArrayList<String> listDevice;
    public BLEService mService;
    public BLEService2 mService2;
    // public DownloadService mServiceDownload;
    public SlidingDrawer slidingDrawer;
    private SharedPreferences sp;

    public boolean isSending() {
        return this.isSending;
    }

    public void setIsSending(boolean isSending2) {
        this.isSending = isSending2;
    }

    public void onCreate() {
        myApp = this;
        this.sp = getSharedPreferences(Global.KEY_MAX, 0);
        this.editor = this.sp.edit();
        this.filePath = getFilesDir().getPath();
        Log.d("filePath", this.filePath);
        //initFace();
        initDeviceName();
        //FileHelper.cutFile(Global.FILE_NAME_PORTRAIT, FileHelper.PATH_PORTRAIT_NEW + FileHelper.FILE_NAME_PORTRAIT);
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();
        initServiceConnection();
        super.onCreate();
    }

    private void initServiceConnection() {
        bindService(new Intent(this, BLEService2.class), this.myServiceConnection, Context.BIND_AUTO_CREATE);
    }

    private ServiceConnection myServiceConnection = new ServiceConnection() {
        /* class com.gzgamut.smart_movement.main.MainActivity2.AnonymousClass5 */

        public void onServiceDisconnected(ComponentName name) {
            MyApp.getIntance().mService2 = null;
            MyApp.this.initServiceConnection();
        }

        public void onServiceConnected(ComponentName name, IBinder service) {
            MyApp.getIntance().mService2 = ((BLEService2.LocalBinder) service).getService();
            //MyLogHelper.loge("MainActivity2", "onServiceConnected");
            EventBus.getDefault().post(new ServiceRegistSuccessEvent());
        }
    };

    public static MyApp getIntance() {
        return myApp;
    }

    public SharedPreferences getSharedPreferences() {
        return this.sp;
    }

    public SharedPreferences.Editor getEditor() {
        return this.editor;
    }

    public String getFilePath() {
        return this.filePath;
    }

    public SlidingDrawer getSlidingDrawer() {
        return this.slidingDrawer;
    }

    public void setSlidingDrawer(SlidingDrawer slidingDrawer2) {
        this.slidingDrawer = slidingDrawer2;
    }

    public void initFace() {
        this.face_number = Typeface.createFromAsset(getAssets(), "fonts/Helvetica Condensed.ttf");
        this.face = Typeface.createFromAsset(getAssets(), "fonts/PingFang SC.ttf");
        //  sendBroadcast(new Intent(LocaleChangedReceiver.ACTION_FONT_CHANGED));
    }

    public void initLanguage() {
        //  LaguageHelper.setLanguage(this, LaguageHelper.isSystemLanguage(), LaguageHelper.getLaguageType());
    }

    private void initDeviceName() {
        this.listDevice = new ArrayList<>();
        this.listDevice.add("Wristband");
        this.listDevice.add("SH09");
    }
}
